﻿#region Copyright Notice
// 
// 
// Copyright (c) 2009-2010 Anindya Chatterjee
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 
// 
// 
#endregion

using System.Serialization;
using System.Xml.Serialization;

namespace GCore
{
    /// <summary>
    /// Base Google service object. This class is xml serializable. This class is responsible for 
    /// xml serialization for Google service atom feeds. <see cref="GFeed&lt;TEntry&gt;"/> and <see cref="GEntry"/> extends
    /// this class to be serializable.
    /// </summary>
    public class GObject : IXObject
    {
        #region IXObject Members

        /// <summary>
        /// Gets and sets default xml namespace for the object.
        /// </summary>
        [XmlIgnore]
        public string DefaultNameSpace { get; set; }

        /// <summary>
        /// Gets and sets the collection of the xml namespaces for the object.
        /// </summary>
        [XmlNamespaceDeclarations]
        public XmlSerializerNamespaces XmlNamespaceCollection { get; set; }

        /// <summary>
        /// Executes routines just after deserialization.
        /// </summary>
        public virtual void Init()
        {
        }

        /// <summary>
        /// Executes routines just before serialization.
        /// </summary>
        public virtual void Close()
        {
            if (XmlNamespaceCollection == null)
                XmlNamespaceCollection = new XmlSerializerNamespaces();
            XmlNamespaceCollection.Add("gd", "http://schemas.google.com/g/2005");
            XmlNamespaceCollection.Add("openSearch", "http://a9.com/-/spec/opensearch/1.1/");

            DefaultNameSpace = "http://www.w3.org/2005/Atom";
        }

        #endregion
    }
}